package me.shiqiang.im.service;

import me.shiqiang.im.dao.RouterServerNodeDao;
import me.shiqiang.im.domain.RouterServerNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * Created by maliangxue on 2018/4/15.
 */
@Service
public class RouterServerNodeServer {

    @Autowired
    RouterServerNodeDao routerServerNodeDao;


    @Autowired
    StringRedisTemplate stringRedisTemplate;

    public void save(RouterServerNode routerServerNode){
        routerServerNodeDao.save(routerServerNode);
    }

    public List<String> findAll(){
        List<String> ips=new ArrayList<>();
        Iterable<RouterServerNode> nodes=routerServerNodeDao.findAll();
        for (RouterServerNode serverNode : nodes) {
            ips.add(serverNode.getAddress());
        }
        return ips;
    }
}
